#ifndef SOLUTION_H_
#define SOLUTION_H_
#include <string>
#include <algorithm>
using namespace std;
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		if(s.size() <= 0)
			return 0;
		size_t lastPos[127];
		for(size_t i=0;i<127;i++)
			lastPos[i] = string::npos;

		int maxLen = 1, curLen = 1;
		lastPos[s[0]] = 0;
		for(size_t i=1;i<s.size();i++)
		{
			if((lastPos[s[i]] != string::npos) && ((i-curLen)<=lastPos[s[i]]))
			{
				curLen = i-lastPos[s[i]];
			}
			else
			{
				curLen++;
			}
			maxLen = max(maxLen,curLen);
			lastPos[s[i]] = i;
		}

		return maxLen;
    }
};
#endif